package com.cfw.collection;

import java.util.Enumeration;
import java.util.Map;
import java.util.Stack;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TreeSearchLog {

	private static final Logger logger = LoggerFactory.getLogger(TreeSearchLog.class); 
	
	public static void logging(final String event) {
		logger.debug(String.format("*** [%-36s]", event));
	}

	public static void logging(final String event, final String target, final Object... pars) {
		final StringBuffer buf = new StringBuffer();
		
		buf.append(String.format("*** [%-20s/%-15s]", event, target));
		
		if (pars.length > 0) {
			for (int i = 0; i < pars.length; i++) {
				if (pars[i] == null) {
					buf.append(" *** null");
				} else
				if (pars[i] instanceof DefaultMutableTreeNode) {
					final DefaultMutableTreeNode node =	(DefaultMutableTreeNode)pars[i];
					
					if (node.getUserObject() != null) {
						Map<String, String> map = (Map<String, String>)node.getUserObject();
						buf.append(String.format(" *** [%-30s]", map.toString()));
					}
				} else {
					buf.append(String.format(" *** [%-30s]", pars[i].toString()));
				}
			}
		}
		logger.debug(buf.toString());
	}
	
	public static void logging(final DefaultMutableTreeNode tree) {
		final Enumeration<TreeNode> allnode = tree.depthFirstEnumeration();
		
		while (allnode.hasMoreElements()) {
			final TreeNode eachnode =	allnode.nextElement();

			logger.debug("node:" + eachnode.toString() + "," + (eachnode.getParent() == null ? "no parent" : eachnode.getParent().toString()));
		}
	}
	
}
